package com.putable.nmc.dmv.simulation.tests;

import java.io.FileWriter;
import java.io.IOException;

import junit.framework.TestCase;

import com.putable.nmc.dmv.simulation.Simulation;

public class SimulationTest extends TestCase {
	
	private String[] worldFilePath = {
		"staff",
		"world",
        };
	//Writes to the world and staff files
	private void writeToFile(String staff, String world) throws IOException{
		FileWriter staffWriter = new FileWriter("staff");
		staffWriter.write(staff);
		staffWriter.flush();
		FileWriter worldWriter = new FileWriter("world");
		worldWriter.write(world);
		worldWriter.flush();
	}
		
	public void testDefault() throws IOException{
		String staffLoader = "35000.0\tLast arrival time\n"
	        + "0 11 0\tStaff\n";
		String worldLoader = "Builtin default world\n"
            + "350 DMV capacity\n"
            + "27 43 81   Task Costs\n"
            + "64134 87341 32100   Staff Costs (mgr, gtlr, btlr)\n"
            + "3600 20 100 30 200 40 300 STUDENT wait (weight time)*tasks\n"
            + "3000 20 60 30 70 40 100 BIKER wait (weight time)*tasks\n"
            + "900 1 50 1 100 1 150    WORKER wait (weight time)*tasks\n"
            + "2400 2 500 2 600 2 700    RETIREE wait (weight time)*tasks\n"
            + "10   Number of customer distributions\n"
            + "0 3600 100000 100000 120 180\n"
            + "3600 7200 100000 100000 60 120\n"
            + "7200 10800 10000 100000 10000 120\n"
            + "10800 14400 1000 5000 10000 180\n"
            + "14400 18000 500 5000 300 1000\n"
            + "18000 21600 10 10 10 30\n" + "21600 25200 200 100 1000 60\n"
            + "25200 28800 200 600 10000 120\n"
            + "28800 32400 100 300 10000 600\n"
            + "32400 36000 30 200 300 900\n";
		writeToFile(staffLoader, worldLoader);
		Simulation demo = new Simulation(worldFilePath);
		assertTrue(demo.run());
	}
	
	public void testAckleysWorld() throws IOException{
		String staffLoader = "35000.0\tLast arrival time\n"
	        + "0 130 0\tStaff\n";
		String worldLoader = "Large world with surges\n"
			+"900 DMV capacity\n"
			+"17 31 77   Task Costs\n"
			+"150000 93000 43000   Staff Costs (mgr, gtlr, btlr)\n"
			+"3600 20 110 30 120 40 130 STUDENT wait (weight time)*tasks\n"
			+"3000 20 60 30 70 40 100 BIKER wait (weight time)*tasks\n"
			+"900 1 50 1 100 1 150    WORKER wait (weight time)*tasks\n"
			+"3000 2 300 3 400 4 400    RETIREE wait (weight time)*tasks\n"
			+"6   Number of customer distributions\n"
			+"0 1200 60 180 3 6                     7-7:20   opening rush\n"
			+"1200 3600 120 240 240 90              7:20-8   A.M. surge\n"
			+"3600 16200 700 1600 400 60            8-11:30  morning\n"
			+"16200 21600 3 4 5 6                   11:30-1  lunch\n"
			+"21600 33300 300 600 1000 120          1-4:15   afternoon\n"
			+"33300 36000 4 2 30 2                  4:15-5   P.M. surge";
		writeToFile(staffLoader, worldLoader);
		Simulation demo = new Simulation(worldFilePath);
		assertTrue(demo.run());
	}
	
	public void testLoader() throws IOException{
		String staffLoader = "36000.0\tLast arrival time\n"
	        + "2 1 5\tStaff\n";
		String worldLoader = "Todd's World\n"
	        + "50 DMV capacity\n"
	        + "27 43 81   Task Costs\n"
	        + "64134 87341 32100   Staff Costs (mgr, gtlr, btlr)\n"
	        + "3600 20 100 30 200 40 300 STUDENT wait (weight time)*tasks\n"
	        + "3000 20 60 30 70 40 100 BIKER wait (weight time)*tasks\n"
	        + "900 1 50 1 100 1 150    WORKER wait (weight time)*tasks\n"
	        + "2400 2 500 2 600 2 700    RETIREE wait (weight time)*tasks\n"
	        + "2   Number of customer distributions\n"
	        + "0 3600 100000 100000 120 180\n"
	        + "3600 7200 100000 100000 60 120\n";
		writeToFile(staffLoader, worldLoader);
		Simulation demo = new Simulation(worldFilePath);
		
		assertTrue(demo.run());
	}
	
	public void testManagers() throws IOException{
		String staffLoader = "36000.0\tLast arrival time\n"
	        + "40 0 0\tStaff\n";
		String worldLoader = "Todd's World\n"
	        + "50 DMV capacity\n"
	        + "27 43 81   Task Costs\n"
	        + "64134 87341 32100   Staff Costs (mgr, gtlr, btlr)\n"
	        + "3600 20 100 30 200 40 300 STUDENT wait (weight time)*tasks\n"
	        + "3000 20 60 30 70 40 100 BIKER wait (weight time)*tasks\n"
	        + "900 1 50 1 100 1 150    WORKER wait (weight time)*tasks\n"
	        + "2400 2 500 2 600 2 700    RETIREE wait (weight time)*tasks\n"
	        + "2   Number of customer distributions\n"
	        + "0 3600 100000 100000 120 180\n"
	        + "3600 7200 100000 100000 60 120\n";
		writeToFile(staffLoader, worldLoader);
		Simulation demo = new Simulation(worldFilePath);
		
		assertTrue(!demo.run());
	}
	
	public void testGoodTellers() throws IOException{
		String staffLoader = "36000.0\tLast arrival time\n"
	        + "0 40 0\tStaff\n";
		String worldLoader = "Todd's World\n"
	        + "50 DMV capacity\n"
	        + "27 43 81   Task Costs\n"
	        + "64134 87341 32100   Staff Costs (mgr, gtlr, btlr)\n"
	        + "3600 20 100 30 200 40 300 STUDENT wait (weight time)*tasks\n"
	        + "3000 20 60 30 70 40 100 BIKER wait (weight time)*tasks\n"
	        + "900 1 50 1 100 1 150    WORKER wait (weight time)*tasks\n"
	        + "2400 2 500 2 600 2 700    RETIREE wait (weight time)*tasks\n"
	        + "2   Number of customer distributions\n"
	        + "0 3600 100000 100000 120 180\n"
	        + "3600 7200 100000 100000 60 120\n";
		writeToFile(staffLoader, worldLoader);
		Simulation demo = new Simulation(worldFilePath);

		assertTrue(!demo.run());
	}
	
	public void testBadTellers() throws IOException{
		String staffLoader = "36000.0\tLast arrival time\n"
	        + "0 0 50\tStaff\n";
		String worldLoader = "Todd's World\n"
	        + "50 DMV capacity\n"
	        + "27 43 81   Task Costs\n"
	        + "64134 87341 32100   Staff Costs (mgr, gtlr, btlr)\n"
	        + "3600 20 100 30 200 40 300 STUDENT wait (weight time)*tasks\n"
	        + "3000 20 60 30 70 40 100 BIKER wait (weight time)*tasks\n"
	        + "900 1 50 1 100 1 150    WORKER wait (weight time)*tasks\n"
	        + "2400 2 500 2 600 2 700    RETIREE wait (weight time)*tasks\n"
	        + "2   Number of customer distributions\n"
	        + "0 3600 100000 100000 120 180\n"
	        + "3600 7200 100000 100000 60 120\n";
		writeToFile(staffLoader, worldLoader);
		Simulation demo = new Simulation(worldFilePath);
		
		assertTrue(!demo.run());
	}
	
	public void testCapacity() throws IOException{
		String staffLoader = "36000.0\tLast arrival time\n"
	        + "3 4 9\tStaff\n";
		String worldLoader = "Todd's World\n"
	        + "1 DMV capacity\n"
	        + "27 43 81   Task Costs\n"
	        + "64134 87341 32100   Staff Costs (mgr, gtlr, btlr)\n"
	        + "3600 20 100 30 200 40 300 STUDENT wait (weight time)*tasks\n"
	        + "3000 20 60 30 70 40 100 BIKER wait (weight time)*tasks\n"
	        + "900 1 50 1 100 1 150    WORKER wait (weight time)*tasks\n"
	        + "2400 2 500 2 600 2 700    RETIREE wait (weight time)*tasks\n"
	        + "2   Number of customer distributions\n"
	        + "0 3600 100000 100000 120 180\n"
	        + "3600 7200 100000 100000 60 120\n";
		writeToFile(staffLoader, worldLoader);
		Simulation demo = new Simulation(worldFilePath);

		assertTrue(!demo.run());
	}
	
	public void testCosts() throws IOException{
		String staffLoader = "36000.0\tLast arrival time\n"
	        + "2 4 9\tStaff\n";
		String worldLoader = "Todd's World\n"
	        + "50 DMV capacity\n"
	        + "1 2 3   Task Costs\n"
	        + "64134 87341 32100   Staff Costs (mgr, gtlr, btlr)\n"
	        + "3600 20 100 30 200 40 300 STUDENT wait (weight time)*tasks\n"
	        + "3000 20 60 30 70 40 100 BIKER wait (weight time)*tasks\n"
	        + "900 1 50 1 100 1 150    WORKER wait (weight time)*tasks\n"
	        + "2400 2 500 2 600 2 700    RETIREE wait (weight time)*tasks\n"
	        + "2   Number of customer distributions\n"
	        + "0 3600 100000 100000 120 180\n"
	        + "3600 7200 100000 100000 60 120\n";
		writeToFile(staffLoader, worldLoader);
		Simulation demo = new Simulation(worldFilePath);
		
		assertTrue(!demo.run());
	}
	
	public void testStaffCosts() throws IOException{
		String staffLoader = "36000.0\tLast arrival time\n"
	        + "2 4 9\tStaff\n";
		String worldLoader = "Todd's World\n"
	        + "50 DMV capacity\n"
	        + "1 2 3   Task Costs\n"
	        + "64134 87341 32100   Staff Costs (mgr, gtlr, btlr)\n"
	        + "3600 20 100 30 200 40 300 STUDENT wait (weight time)*tasks\n"
	        + "3000 20 60 30 70 40 100 BIKER wait (weight time)*tasks\n"
	        + "900 1 50 1 100 1 150    WORKER wait (weight time)*tasks\n"
	        + "2400 2 500 2 600 2 700    RETIREE wait (weight time)*tasks\n"
	        + "2   Number of customer distributions\n"
	        + "0 3600 100000 100000 120 180\n"
	        + "3600 7200 100000 100000 60 120\n";
		writeToFile(staffLoader, worldLoader);
		Simulation demo = new Simulation(worldFilePath);
		
		assertTrue(!demo.run());
	}
}
